package com.formina.stars;

import com.formina.engine.Engine;
import com.formina.engine.GameView;
import com.formina.engine.Pointer;

import android.content.Context;
import android.view.MotionEvent;

public class StarGameView extends GameView{
	private StarRenderer renderer;
	public StarGameView(Context context) {
		super(context);
		renderer = new StarRenderer();
		this.setRenderer(renderer);		
		//this.setRenderMode(RENDERMODE_WHEN_DIRTY);
	}

	int mode = StarRenderer.MODE_NONE;
	@Override
	public boolean onTouchEvent(MotionEvent ev){	
		final MotionEvent ev1 = ev;
		final int aid = ev.getActionIndex();
		final int action = ev.getAction();
		final int actionCode = action & MotionEvent.ACTION_MASK;
		Pointer ap;
		ap = Engine.GetPointer(ev.getPointerId(aid));
		if(actionCode == MotionEvent.ACTION_UP || actionCode==MotionEvent.ACTION_POINTER_UP){
			ap.Mode=StarRenderer.MODE_FINGER_UP;
		}else{
			if(ap.Mode==StarRenderer.MODE_FINGER_UP){
				ap.Mode=StarRenderer.MODE_NONE;
			}
		}

		for(int i=0;i<ev.getPointerCount();i++){
			final Pointer po = Engine.GetPointer(ev.getPointerId(i));
			po.x = ev.getX(i);
			po.y = ev.getY(i);
			//Log.d(String.valueOf(i), String.valueOf(p.x)+ "|" + String.valueOf(p.y) + " | " + String.valueOf(p.Mode));
			queueEvent(new Runnable() {
	            // This method will be called on the rendering
	            // thread:
	            public void run() {
	                renderer.HandleTouch(po);
	            }});
		}
		
		return true;
		
	}	
	
	int re,gr,bl;
	boolean random;
	public void SetColor(int r, int g, int b, boolean useRandom){
		re = r; gr = g; bl = b; random = useRandom;
		queueEvent(new Runnable() {

			// This method will be called on the rendering
            // thread:
            public void run() {
                renderer.setColor(re, gr,bl,random);
            }});
	}
	
}
